package org.springside.examples.miniweb.service.dictionary;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import org.springside.examples.miniweb.entity.dictionary.City;
import org.springside.examples.miniweb.dao.dictionary.CityDao;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;

@Service
@Transactional
public class CityManager {
	@Autowired
	private CityDao cityDao;

	// City Manager //
	@Transactional(readOnly = true)
	public City getCity(Long id) {
		return cityDao.get(id);
	}

	@Transactional(readOnly = true)
	public List<City> getAllCity() {
		return cityDao.getAll();
	}
	
	@Transactional(readOnly = true)
	public Page<City> searchCity(final Page<City> page, final List<PropertyFilter> filters) {
		return cityDao.findPage(page, filters);
	}	
	
	@Transactional(readOnly = true)
	public List<City> searchCityByProvinceId(Integer id) {
		return cityDao.findBy("pid", id);
	}	
	
	public void saveCity(City city) {
		cityDao.save(city);
	}

	public void deleteCity(Long id) {
		cityDao.delete(id);
	}
}

